<?php

$_this =& $this;

/* @var $_this View */
/* @var $form FormHelper */
/* @var $editForm EditFormHelper */
/* @var $html HtmlHelper */
/* @var $ehtml EHtmlHelper */
/* @var $javascript JavascriptHelper */
/* @var $jqax JqaxHelper */
/* @var $filterBlock FilterBlock */

?><?=$filterBlock->create('Filter', array('url'=>("/{$url_part}/")));?><?php

	if (Auth::o()->is('admin')) {
    	$filterBlock->add(
            $form->label('client_id', __d($po_domain, 'client_field', true).': ',array('class'=>'filter')).
            $form->select('client_id', $clients_list, null, array('label' => false), '')
    	);
	}
	$filterBlock->add(
        $form->label('from_date', __d($po_domain, 'created_field', true).': '.mb_strtolower(__d(null, 'from_period', true), DEFAULT_CHARSET).' ',array('class'=>'filter')).
		$calendar->date('from_date', false, array('size' => '10', 'label' => false)).
		' '.
		$form->label('to_date', __d(null,'to_period', true).' ',array('class'=>'filter')).
		$calendar->date('to_date', false, array('size' => '10', 'label' => false))
	);
    $filterBlock->sep();
	$filterBlock->add(
        $form->label('type', __d($po_domain, 'type', true).': ',array('class'=>'filter')).
        $form->select('type', $types_list, null, array('label' => false), '')
	);
	$filterBlock->add(
        $form->label('searche', __d(null, 'searche_filter', true).': ', array('class'=>'filter')).
		$form->text('searche', false, array('size' => '17', 'label' => false))
	);
?><?=$filterBlock->end();?><?php

?><br /><?php

if (Auth::o()->is('admin') && !empty($in_queue_messages)) {
    $queue_link_title = "<strong>{$in_queue_messages}</strong> ".__d($po_domain, 'message_plurar_'.plurar_mode_ru($in_queue_messages), true);
    $queue_link_url = array('controller' => 'emails', 'action' => 'list_of');
    $queue_link = $html->link($queue_link_title, $queue_link_url, array(), false, false);
    ?><?=sprintf(__d($po_domain, 'The queue for sending contains %s.', true), $queue_link);?><?php
    ?><br /><?php
    ?><br /><?php
}

if (count($list->rows)) {

?><?=$this->renderElement('pagination', array('paging' => $list->pagination));?><?php

?><table class="table" cellpadding="0"><?php
?><thead><?php
    ?><tr><?php
        ?><th class="nw"><?php
            ?><?=$this->renderElement('sort_field', array('obj' => $list->order, 'field' => 'send_date', 'domain'=>$po_domain));?><?php
        ?></th><?php
        ?><th class="nw"><?php
            ?><?=$this->renderElement('sort_field', array('obj' => $list->order, 'field' => 'type', 'domain'=>$po_domain));?><?php
        ?></th><?php
    	if (Auth::o()->is('admin')) {
            ?><th class="nw"><?php
                ?><?=$this->renderElement('sort_field', array('obj' => $list->order, 'field' => 'client', 'domain'=>$po_domain));?><?php
            ?></th><?php
        }
        ?><th class="nw"><?php
            ?><?=$this->renderElement('sort_field', array('obj' => $list->order, 'field' => 'author', 'domain'=>$po_domain));?><?php
        ?></th><?php
        ?><th class="nw"><?php
            ?><?=$this->renderElement('sort_field', array('obj' => $list->order, 'field' => 'recepient', 'domain'=>$po_domain));?><?php
        ?></th><?php
		?><th class="nw"><?php
            ?><?=$this->renderElement('sort_field', array('obj' => $list->order, 'field' => 'test', 'domain'=>$po_domain));?><?php
        ?></th><?php
        if (empty($this->data['Filter']['type']) || ($this->data['Filter']['type'] == 'REPORT')) {
    		?><th class="nw"><?php
                ?><?=$this->renderElement('sort_field', array('obj' => $list->order, 'field' => 'report', 'domain'=>$po_domain));?><?php
            ?></th><?php
        }
		?><th class="nw"></th><?php
    ?></tr><?php
?></thead><?php
?><tbody><?php

    $i = 0;
    foreach ($list->rows as $item) {
        $class = '';
    	if ($i++ % 2 != 0) {
    		$sep = strlen($class) ? ' ' : '';
    		$class .= $sep.'altrow';
    	}
    	$class = strlen($class) ? ' class="'.$class.'"' : '';

        ?><tr <?=$class;?>><?php
    		?><td class="nw"><?php
                ?><?=Date::Short(Date::SQL2UNIX($item[$modelName]['send_date']));?><?php
            ?></td><?php
    		?><td class="nw"><?php
                ?><?=$types_list[$item[$modelName]['type']];?><?php
            ?></td><?php
            if (Auth::o()->is('admin')) {
        		?><td class="nw"><?php
                    ?><?=$item['Client']['name'];?><?php
                ?></td><?php
            }
    		?><td class="nw"><?php
                if (Auth::o()->is('client_admin')) {
                    if (!empty($item[$modelName]['author_admin_id'])) {
                        ?><span class="additional_msg"><?php
                            ?><?=__d('passes', 'admin_for_client', true);?><?php
                        ?></span><?php
                    } elseif (!empty($item[$modelName]['author_client_admin_id'])) {
                        ?><?=$html->link($item['AuthorClientAdmin']['username'], "/client-admins/".$item['AuthorClientAdmin']['id']."/", array(), false, false);?><?php
                    } else {
                        ?>—<?php
                    }
                } else {
                    if (!empty($item[$modelName]['author_admin_id'])) {
                        ?><?=$html->link($item['AuthorAdmin']['username'], "/admins/".$item['AuthorAdmin']['id']."/", array(), false, false);?><?php
                        ?><div class="note"><?php
                            ?><?=__d('passes', 'admin', true);?><?php
                        ?></div><?php
                    } elseif (!empty($item[$modelName]['author_client_admin_id'])) {
                        ?><?=$html->link($item['AuthorClientAdmin']['username'], "/client-admins/".$item['AuthorClientAdmin']['id']."/", array(), false, false);?><?php
                        ?><div class="note"><?php
                            ?><?=__d('passes', 'client_admin', true);?><?php
                        ?></div><?php
                    } else {
                        ?>—<?php
                    }
                }
            ?></td><?php
            ?><td class="nw"><?php
                if (!empty($item[$modelName]['client_admin_id'])) {
                    ?><?=$html->link($item['ClientAdmin']['username'], "/client-admins/".$item['ClientAdmin']['id']."/", array(), false, false);?><?php
                    ?><div class="note"><?php
                        ?><?=__d('passes', 'client_admin', true);?><?php
                    ?></div><?php
                } else {
                    ?><?=$html->link($item['Candidate']['surname'].' '.$item['Candidate']['name'], "/candidates/".$item['Candidate']['id']."/", array(), false, false);?><?php
                    ?><div class="note"><?php
                        ?><?=__d('passes', 'candidate', true);?><?php
                    ?></div><?php
                }
            ?></td><?php
            ?><td class="nw"><?php
                ?><?=(!empty($item['Test']['id'])) ? $item['Test']['name'] : "—";?><?php
            ?></td><?php
            if (empty($this->data['Filter']['type']) || ($this->data['Filter']['type'] == 'REPORT')) {
                ?><td class="nw"><?php
                    ?><?=(!empty($item['Report']['id'])) ? $item['Report']['name'] : "—";?><?php
                ?></td><?php
            }
            ?><td class="nw actions"><?php
                ?><table class="sys_clear" cellpadding="0"><?php
                ?><tr class="sys_clear"><?php
                    ?><?=$ehtml->iconLink("edit", __d(null, 'view', true), "/{$url_part}/{$item[$modelName][$PKName]}/");?><?php
                ?></tr><?php
                ?></table><?php
            ?></td><?php
    	?></tr><?php
    }

?></tbody><?php
?></table><?php

?><?=$this->renderElement('pagination', array('paging' => $list->pagination));?><?php

} else {
    ?><span class="additional_msg"><?php
        ?><?=__d($po_domain, 'List is empty', true);?><?php
    ?></span><?php
}

?>